﻿using System;
using NUnit.Framework;

namespace cshape_demo
{
    [TestFixture]
    public class TypeConvter
    {
        /**
         * 说明:
         * 1. Convert是c#内置的转换类;
         *     - 在将float转换为bool类型时, 0会转换为false, 非0会转换为true.
         */
        [Test]
        public void TestToInt()
        {
            float f1 = 12.1F;
            float f2 = 0F;
            float f3 = -12.1F;

            bool b1 = Convert.ToBoolean(f1);
            bool b2 = Convert.ToBoolean(f2);
            bool b3 = Convert.ToBoolean(f3);
            
            Console.WriteLine(b1);
            Console.WriteLine(b2);
            Console.WriteLine(b3);
        }

        [Test]
        public void TestToString()
        {
            String s1 = "33";
            // 这种字符串将转换失败
            String s2 = "33d";
            // 这种也会转换失败
            String s3 = "33dd";

            Console.WriteLine(Convert.ToDouble(s1));
            //Console.WriteLine(Convert.ToDouble(s2));
            //Console.WriteLine(Convert.ToDouble(s3));
        }

        [Test]
        public void CoercionConvter()
        {
            double d1 = 12D;
            int i = (int) d1;

            Console.WriteLine(i.GetType());
        }

    }
}